<template>
  <div class="app-container">
    <!--查询表单-->
    <el-form :inline="true">
      <el-form-item label="关键字">
        <el-input v-model="keyword" placeholder="姓名/手机/身份证" />
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="fetchData()"> 查询</el-button>

      <el-button type="default" @click="resetData()"> 清空</el-button>
    </el-form>

    <!-- 列表 -->
    <el-table :data="list" stripe>
      <el-table-column label="序号" width="70" align="center">
        <template slot-scope="scope"> {{ (page - 1) * limit + scope.$index + 1 }}</template>
      </el-table-column>

      <el-table-column prop="name" label="姓名" />
      <el-table-column prop="mobile" label="手机" />
      <el-table-column prop="idCard" label="身份证号" width="200" />

      <el-table-column label="性别" width="80">
        <template slot-scope="scope"> {{ scope.row.sex === 1 ? '男' : '女' }}</template>
      </el-table-column>

      <el-table-column prop="age" label="年龄" width="80" />
      <el-table-column label="是否结婚" width="120">
        <template slot-scope="scope"> {{ scope.row.marry ? '是' : '否' }}</template>
      </el-table-column>

      <el-table-column label="状态" width="100">
        <template slot-scope="scope">
          {{ scope.row.status }}
        </template>
      </el-table-column>

      <el-table-column prop="createdTime" label="申请时间" width="160" />

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <router-link :to="'/service/borrower/detail/' + scope.row.id">
            <el-button v-if="scope.row.status === 1" type="warning" size="mini"> 审批</el-button>
            <el-button v-else type="primary" size="mini"> 查看</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-col :span="20" :xs="24" class="right-align">
      <pagination v-show="total > 0"
                  :total="total" :page.sync="searchObj.pageNum" :limit.sync="searchObj.pageSize"
                  @pagination="fetchData" />
    </el-col>

  </div>
</template>

<script>
import borrowerApi from '@/api/service/borrower'

export default {
  name: 'List',
  data() {
    return {
      list: null, // banner列表
      total: 0, // 数据库中的总记录数
      page: 1, // 默认页码
      limit: 10, // 每页记录数
      keyword: '', // 查询表单对象
      searchObj: {
        pageNum: 1,
        pageSize: 10
      } // 查询条件
    }
  },

  // 生命周期函数：内存准备完毕，页面尚未渲染
  created() {
    this.fetchData()
  },

  methods: {
    // 加载banner列表数据
    fetchData() {
      borrowerApi.getPageList(this.keyword, this.searchObj).then(response => {
        this.list = response.data.list
        this.total = response.data.total
      })
    },

    // 重置表单
    resetData() {
      this.keyword = ''
      this.fetchData()
    }
  }
}
</script>

<style scoped>
.right-align {
  text-align: right;
}
</style>
